const useDebounce = (callback, delay, immediate = true) => {
  let timerId = null

  return (...args) => {
    clearTimeout(timerId)

    if (immediate && !timerId) {
      callback(...args)
    }

    timerId = setTimeout(() => {
      callback(...args)
    }, delay)
  }
}


export default useDebounce;